package com.idp.system.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.idp.common.base.BaseController;
import com.idp.common.model.PageModel;
import com.idp.common.model.ResultModel;
import com.idp.system.dto.SysFileDto;
import com.idp.system.dto.SysFileSearchDto;
import com.idp.system.service.SysFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文件表Controller
 * @author King
 */
@Api(tags="文件服务")
@RestController
@RequestMapping("/file/")
public class SysFileController extends BaseController {

	@Autowired
	private SysFileService sysFileService;

	/**
	 * 分页查询
	 * @param sysFileSearchDto
	 * @return
	 */
	@ApiOperation(value="分页查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "page", value = "页数", paramType = "query", required = true, defaultValue = "1"),
			@ApiImplicitParam(name = "rows", value = "每页行数", paramType = "query", required = true, defaultValue = "10")
	})
	@PostMapping("findByPage")
	public ResultModel<PageModel<SysFileDto>> findByPage(@RequestBody SysFileSearchDto sysFileSearchDto) {
		return ResultModel.success(sysFileService.findByPage(sysFileSearchDto));
	}

	/**
	 * 通过id查询
	 * @param sysFileDto
	 * @return
	 */
	@ApiOperation(value="通过id查询")
	@ApiOperationSupport(includeParameters = {"sysFileDto.id"})
	@PostMapping("getById")
	public ResultModel<SysFileDto> getById(@RequestBody SysFileDto sysFileDto) {
		return ResultModel.success(sysFileService.getById(sysFileDto.getId()));
	}

}
